Dynamic memory management
From Cppreference
< cpp
| C++ Standard Library | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
| Utilities library | ||||||||||||
| Dynamic memory management | ||||||||||||
| Template:cpp/memory/sidebar content | ||||||||||||
Contents |
[edit] Low level memory management
[edit] Allocators
Allocators are class templates encapsulating memory allocation strategy. This allows generic containers to decouple memory management from the data itself.
| The default allocator. Before C++0x any allocator had to provide the interface (but not necessarily implementation), identical to one of the default allocator, also it could not have nonstatic data. In C++x0 these two rules are relaxed, allocators can be implemented through allocator_traits (class template) | ||
| Provides standard interface to access the interface and properties of particular allocator (class template) | ||
| Implements multi-level allocator, which can be used in multi-level containers to specify allocator for elements in each particular level (class template) | ||
[edit] Uninitialized storage
Several utilities are provided to initialize raw storage
| copies a range of objects to uninitialized area of memory (function template) | ||
| copies a number of objects to uninitialized area of memory (function template) | ||
| copies an object to uninitialized area of memory (function template) | ||
| copies an object to uninitialized area of memory (function template) | ||
[edit] Smart pointers
Smart pointers enable easier and less error prone object lifetime management.
| provides pointer ownership semantics, i.e. only one unique_ptr object can own the given object, which is destroyed when the unique_ptr object referring to it is destroyed (class template) | ||
| provides shared pointer ownership semantics, i.e. multiple shared_ptr instances can manages an object, which is destroyed when the last shared_ptr object referring to it is destroyed (class template) | ||
| holds weak reference to an object already managed by shared_ptr, i.e. the object can be destroyed even there is weak_ptr instance referring to it (class template) | ||
| allows an object to get a shared_ptr referring to itself (class template) | ||
| an exception that is thrown when accessing a weak_ptr which refers to already destroyed object (class template) | ||
| provides unique pointer ownership semantics. This class is deprecated, use unique_ptr instead. (class template) | ||
[edit] Garbage collector support
| declares that an object can not be recycled even if there is no pointer referring to it (function template) | ||
| declares that an object can not be recycled even if there is no pointer referring to it (function template) | ||
| declares that a memory area does not contain pointers (function template) | ||
| declares that a memory area can have pointers (function template) | ||
| returns the implementation's pointer safety (function template) | ||
[edit] Miscellaneous
| provides interface to query information about several properties of pointer-like types (class template) | ||
| obtains actual address of an object, even if the & operator is overloaded (function template) | ||
| aligns a pointer in a buffer (function template) | ||